package org.jmc.refmanager.domain.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="roles")
@NamedQueries({
	@NamedQuery(name = Role.FIND_BY_NAME, 
			query = "SELECT r FROM Role r WHERE r.name = ?1"),
	@NamedQuery(name = Role.FIND_ALL_BUT, 
			query = "SELECT r FROM Role r WHERE r.name <> ?1")
})
public class Role implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String FIND_BY_NAME = "Role.findByName";
	public static final String FIND_ALL_BUT = "Role.findAllBut";
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@Column(name="ROLE_NAME", nullable=false, length=20, unique=true)
	private String name;

	@Column(name="DESCRIPTION", length=64)
	private String description;

	@OneToMany(mappedBy="role", fetch=FetchType.LAZY)
    private Set<User> members = new HashSet<User>(0);
	
	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(final Integer id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * @return the members
	 */
	public Set<User> getMembers() {
		return members;
	}

	/**
	 * @param members the members to set
	 */
	public void setMembers(Set<User> members) {
		this.members = members;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
